// pages/writeEXP/writeEXP.js
var api = require('../../config/api.js');
var util = require('../../utils/util.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    studentTypes: [{
        value: '1',
        name: '国内',
        checked: 'true'
      },
      {
        value: '2',
        name: '海外(含港澳台)'
      },
    ],
    degree: [{
        value: '1',
        name: '本科',
        checked: 'true'
      },
      {
        value: '2',
        name: '硕士',
      },
      {
        value: '3',
        name: 'MBA',
      },
      {
        value: '4',
        name: '硕博连读',
      },
      {
        value: '5',
        name: '博士',
      },
      {
        value: '6',
        name: '博士后',
      },
      {
        value: '7',
        name: '其他',
      },
    ],
    checkboxChecked: false,
    interviewTitle: "", //面试标题
    studentType: "1",
    offerType: "1",
    schoolName: "",
    interviewSpecial: "",
    projectName: "",
    interviewDetail: "",
    isAnonymous: "",

  },
  isHideNameChange: function(e) {
    let isHideName = this.data.checkboxChecked;
    isHideName = !isHideName;
    console.log(isHideName)
    this.setData({
      checkboxChecked: isHideName,
      isAnonymous: isHideName ? 1 : 0
    })
  },
  studentTypeRadioChange(e) {
    console.log('radio发生change事件，携带value值为：', e.detail.value)
    const studentTypes = this.data.studentTypes;
    for (let i = 0, len = studentTypes.length; i < len; ++i) {
      studentTypes[i].checked = studentTypes[i].value === e.detail.value
    }
    this.setData({
      studentTypes: studentTypes,
      studentType: e.detail.value
    })
  },
  degreeTypeRadioChange(e) {
    console.log('radio发生change事件，携带value值为：', e.detail.value)
    const degree = this.data.degree;
    for (let i = 0, len = degree.length; i < len; ++i) {
      degree[i].checked = degree[i].value === e.detail.value
    }
    this.setData({
      degree: degree,
      offerType: e.detail.value
    })
  },
  //发布面经
  interviewSubmit: function(e) {
    var userInfo = wx.getStorageSync('userInfo') //获取用户
    var interviewTitle = this.data.interviewTitle; //获取面试标题
    var studentType = this.data.studentType; //获取考生类型   1为国内 2为海外
    var offerType = this.data.offerType; //获取offer学位 
    var schoolName = this.data.schoolName; //获取院校名称
    var interviewSpecial = this.data.interviewSpecial; //获取面试专业
    var projectName = this.data.projectName; //获取项目名称
    var interviewDetail = this.data.interviewDetail; //获取面试过程及内容
    var isHideName = this.data.checkboxChecked; //是否匿名  true是匿名  false是不匿名
    var interview = this.data;
    interview.userId = userInfo.id;
    interview.userName = userInfo.nickName;

    if (!interviewTitle) {
      wx.showToast({
        title: '请填写面试标题',
        icon: 'none',
        duration: 1000,
        mask: true
      })
    } else if (!schoolName) {
      wx.showToast({
        title: '请填写院校名称',
        icon: 'none',
        duration: 1000,
        mask: true
      })
    } else if (!interviewSpecial) {
      wx.showToast({
        title: '请填写面试专业',
        icon: 'none',
        duration: 1000,
        mask: true
      })
    } else if (!projectName) {
      wx.showToast({
        title: '请填写项目名称',
        icon: 'none',
        duration: 1000,
        mask: true
      })
    } else if (!interviewDetail) {
      wx.showToast({
        title: '请填写面试过程及内容',
        icon: 'none',
        duration: 1000,
        mask: true
      })
    } else {
      util.request(api.InterviewAdd, interview, 'POST', true).then(function(res) {
        if (res.code === 200) {
          wx.setStorageSync('successSubmit', true);
          wx.switchTab({
            url: '../index/index'
          })
        }
      })
    }



  },
  setValue: function(e) {
    this.setData({
      [e.currentTarget.dataset.name]: e.detail.value,
      // interViewTitle: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})